﻿using System;
using System.Collections.Generic;

using System.Text;

namespace Flame.Dlr
{

    // NOT CASE SENSITIVE !!!
    public class Languages
    {
        static Dictionary<string, Type> _map = new Dictionary<string, Type>();
        public static Type Get(string name)
        {
            string s = name.ToLower();
            if (!_map.ContainsKey(s)) return null;
            return _map[s];
        }

        static void addIfNotExist(string name, Type type)
        {
            string s = name.ToLower();
            if (!_map.ContainsKey(s))
            {
                _map.Add(s, type);
            }
        }

        public static void Set(Type type, params string[] alternatives_names)
        {

            //if (_map.ContainsKey(name)) return;
            foreach (string s in alternatives_names)
                addIfNotExist(s, type);
            addIfNotExist(type.Name, type);
        }

        static Languages()
        {

            //Set(typeof(NoneExec));
            Set(typeof(NoneExec), "none");
            //Set(typeof(CSharpCompiler));
            Set(typeof(CSharpCompiler), "CSharp");
            Set(typeof(VisualBasicNetCompiler));

        }

        /*public static Type TryTypeFromName(string name)
        {
            Type execType = null;
            try
            {
                execType = Type.GetType("Flame.Dlr." + name);
            }
            catch
            {
                return null;
            }
            return execType;
        }

        public static Type FromName(string name)
        {
            Type execType = null;
            try
            {
                execType = Type.GetType("Flame.Dlr." + name);
            }
            catch
            {
                return null;
            }
            return execType;
        }*/

        public static Type None { get { return typeof(NoneExec); } }

        /*public static Type Parse(string name)
        {
            string name2 = name;

            switch (name.ToLower())
            {
                case "txt":
                    name2 = "NoneExec";
                    break;
                case "cs":
                    name2 = "CSharpCompiler";
                    break;
                case "css":
                    break;

                case "py":
                case "python":
                    name2 = "IronPythonExec";
                    break;
                case "rb":
                case "ruby":
                    break;

                case "ps":

                    break;
            }
            Type t = null;

            try
            {
                t = Type.GetType(name2);
            }
            catch { }
            return t;

        }*/
    }


    /* public enum Languages
     {
         None = 0,
         CSharp = 1 << 0, VisualBasicNet = 1 << 1, FSharp = 1 << 2,
         IronRuby = 1 << 3, IronPython = 1 << 4, Powershell = 1 << 5, Scheme = 1 << 6,
         CSharpScript = 1 << 7, VisualBasicNetScript = 1 << 8, FSharpScript = 1 << 9,
         /*Javascript = 1 << 10,* /
         VisualBasic = 1 << 11, PHP = 1 << 12, VBA = 1 << 13,

         AutoIT = 1 << 20,

         Bad = -1,
         Languages_All = IronRuby + CSharp + CSharpScript + IronPython + Powershell,

         Ruby = IronRuby, Python = IronPython,
         txt = None, cs = CSharp, css = CSharpScript, py = IronPython, rb = IronRuby, ps = Powershell,
         Javascript_ClearScript,
     }*/

}
